<?php
include $_SERVER['DOCUMENT_ROOT'] . '/quocha/lib/DonHang.php';
$donhangOb = new DonHang();
//Xu ly them xoa
$command = '';
$id = '';
$message = array();
if (isset($_GET['command'])) {
    $command = $_GET['command'];
}
if (isset($_GET['id'])) {
    $id = $_GET['id'];
}
if ($command == 'del') {
    if ($donhangOb->xoaDonHang($id)) {
        $message[] = "Xóa thành công";
    } else {
        $message[] = "Xóa thất bại";
    }
}

$dh = $donhangOb->layDonHang();
//-------------------
?>

<div class="grid_10">
    <div class="box round first grid">
        <?php foreach ($message as $mes): ?>
        <div class="message success">
        <p><?php echo $mes; ?></p>
         </div>
        <?php endforeach; ?>
        <h2>Danh sách giỏ hàng</h2>
        <div class="block">

            <table class="data display datatable" id="example">

                <thead>
                    <tr>
                        <th>STT</th>
                        <th>User</th>
                        <th>Trạng thái</th>
                        <th>Ngày đặt hàng</th>
                        <th></th>
                        <th></th>
                        <th></th>
                    </tr>
                </thead>
                <tbody>
                    <?php
                    $i = 0;
                    ?>
                    <?php foreach ($dh as $d): ?>
                        <tr class="odd gradeX">
                            <td><?php echo++$i; ?></td>
                            <td><a href="/admin/chitiet.php?User=<?php echo $d['user'] ?>"><?php echo $d['user'] ?></a></td>
                            <td><?php echo DonHang::$TrangThaiArray[$d['trangthai']] ?></td>
                            <td><?php echo $d['ngaydathang'] ?></td>
                            <td><?php echo "<a href='/quocha/admin/chitietgiohang.php?id=" . $d['id'] . "'>Chi tiết"; ?></td>
                            <td><?php echo "<a href='/quocha/admin/capnhatgiohang.php?id=" . $d['id'] . "'>Sửa"; ?></td>
                            <td><?php echo "<a href='/quocha/admin/giohang.php?command=del&id=" . $d['id'] . "'>Xóa"; ?></td>
                            </td>
                        </tr>
                    <?php endforeach; ?>
                </tbody>
            </table>